<template>
  <div class="page-main" v-title data-title="科研技术列表">
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>科研技术列表</span></div>
    <div class="container">
      <div class="header">
        <a-form layout="inline">
          <a-row type="flex" justify="space-between" align="middle">
            <a-col :xl="{ span: 14 }" :lg="{ span: 11 }">
            <a-button type="primary" v-if="permissions.indexOf('tech:add') > -1" @click="doAdd" style="margin-left: 8px"
              >新增</a-button
            >
            <a-button
              v-if="permissions.indexOf('tech:edit') > -1"
              @click="doEdit"
              style="margin-left: 8px"
              >修改</a-button
            >
            <a-button
              v-if="permissions.indexOf('tech:detail') > -1"
              @click="doDetail"
              style="margin-left: 8px"
              >查看
            </a-button>
            <a-button
              v-if="permissions.indexOf('tech:audit') > -1"
              @click="doAudit"
              style="margin-left: 8px"
              >审核</a-button
            >
            <a-button @click="handlePostExportXls('信息技术报表')" style="margin-left: 10px">导出</a-button>
            <a-button
              v-if="permissions.indexOf('tech:delete') > -1"
              @click="doDel"
              style="margin-left: 8px"
              >删除</a-button
            >
            <a-button @click="searchReset" icon="reload" style="margin-left: 8px">刷新</a-button>
          </a-col>
          <a-col :xl="{ span: 9 }" :lg="{ span: 13 }" class="input-ground">
            <a-input-group compact>
              <a-select v-if="freshKey" v-model="queryParam.searchField" @change="searchFieldChange">
                <a-select-option value="code"> 项目号&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </a-select-option>
                <a-select-option value="name"> 技术名称 </a-select-option>
                <a-select-option value="publishUserName"> 项目经理 </a-select-option>
              </a-select>
              <a-input-search v-model="queryParam.keyword" @search="searchQuery" placeholder="请按照关键字进行搜索" />
            </a-input-group>
            <a-button class="hte-btn del-btn" @click="showSearchForm = true">高级搜索</a-button>
          </a-col>

          </a-row>
        </a-form>

        <a-modal
          :visible="showSearchForm"
          width="70vw"
          :bodyStyle="{ padding: '10px' }"
          title="高级查询"
          @ok="handleToSearch"
          @cancel="showSearchForm = false"
        >
          <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol">
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="状态">
                  <a-select style="width: 100%" v-model="queryParam.status">
                    <a-select-option v-for="d in dicts.statusDic" :value="d.code" :key="d.code">{{ d.name }}</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="技术编号">
                  <a-input v-model="queryParam.code" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="技术名称">
                  <a-input v-model="queryParam.name" />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="技术类别">
                  <a-select style="width: 100%" v-model="queryParam.category">
                    <a-select-option v-for="d in dicts.categoryDic" :value="d.code" :key="d.code">{{ d.name }}</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="项目经理">
                  <a-input v-model="queryParam.publishUserName" />
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </a-modal>
      </div>
      <div class="content-list">
        <a-table
          ref="table"
          bordered
          size="middle"
          :rowKey="rowKey"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :rowSelection="{
            selectedRowKeys: selectedRowKeys,
            onChange: onSelectChange,
            onSelectAll: onSelectAll,
            columnWidth: 1,
          }"
          :loading="loading"
          :scroll="{ x: true }"
          @change="handleTableChange"
        >
        </a-table>
      </div>
    </div>
  </div>
</template>


<script>
import Vue from 'vue'
import { getAction, postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import { ACCESS_TOKEN, USER_NAME } from '@/store/mutation-types'
export default {
  name: 'TechList',
  mixins: [JeecgListMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
  },
  data() {
    return {
      description: '科技信息列表',
      freshKey: true,
      permissions: [],
      myPermission: '/upms/user/getAllPermissionValues',
      /* 勾选导出参数 */
      rowKey: 'id',
      busType: 'TechList',
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'ContractReportInfo',
      },
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '50'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 5,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '项目号',
          align: 'center',
          width: 80,
          dataIndex: 'code',
        },
        {
          title: '技术编号',
          align: 'center',
          width: 100,
          dataIndex: 'fileNoShow',
        },
        {
          title: '技术名称(脱密)',
          align: 'center',
          width: 120,
          dataIndex: 'name',
        },
        {
          title: '关键词',
          align: 'center',
          width: 150,
          dataIndex: 'keyWord',
        },
        {
          title: '产出物形式',
          align: 'center',
          width: 100,
          dataIndex: 'productForm',
        },
        {
          title: '产品名称',
          align: 'center',
          width: 100,
          dataIndex: 'technicalProduct',
        },
        {
          title: '项目经理',
          align: 'center',
          width: 90,
          dataIndex: 'publishUserName',
        },
        {
          title: '技术等级',
          align: 'center',
          width: 60,
          dataIndex: 'techLevel',
        },
        {
          title: '申请人/部门',
          align: 'center',
          width: 120,
          dataIndex: 'createUserName',
          customRender:function (t,r,index) {
            if(r.createUserDept!=null){
              return r.createUserName + '/' + r.createUserDept
            } else {
              return r.createUserName
            }
          },
        },
        {
          title: '申请时间',
          align: 'center',
          width: 120,
          dataIndex: 'createDate',
        },
        {
          title: '查阅次数',
          align: 'center',
          width: 60,
          dataIndex: 'visitsNum',
          sorter: true
        },
        {
          title: '状态',
          align: 'center',
          width: 60,
          dataIndex: 'statusShow',
        },
      ],
      url: {
        list: '/rad/technology/list',
        exportXlsUrl: '/rad/technology/exportXls',
        delete: '/rad/technology/delete',
      },
      dicts: {
        categoryDic: [
          { code: '1', name: '应用技术' },
          { code: '2', name: '快检技术' },
          { code: '3', name: '机理研究' },
        ],
        statusDic:[
          {code:0,name:'创建中'},
          {code:1,name:'审批中'},
          {code:2,name:'已通过'},
          {code:3,name:'不通过'}
        ]
      },
      showSearchForm: false,
      keyword: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      userId: Vue.ls.get(USER_NAME),
    }
  },
  mounted() {
    this.queryParam.searchField = 'code'
    getAction(this.myPermission, { projectId: -1 }).then((res) => {
      if (res.code == 200) {
        this.permissions = res.result
      } else {
        this.$message.warning('加载权限数据失败:' + res.message)
      }
    })
  },
  computed: {},
  methods: {
    searchFieldChange(){
      this.freshKey=!this.freshKey
      this.freshKey=!this.freshKey
    },
    handleToSearch() {
      this.showSearchForm = false
      this.searchQuery()
    },
    searchReset() {
      this.queryParam = {}
      this.queryParam.searchField = 'code'
      this.handleToSearch()
    },
    doAdd() {
      let urlJump = this.$router.resolve({ path: `/techEdit` })
      window.open(urlJump.href, '_blank')
    },
    doEdit() {
      if (this.selectionRows == null || this.selectionRows.length != 1) {
        this.$message.warning('请选择1条数据')
        return
      }
      var record = this.selectionRows[0]
      if (record.createUserId != this.userId) {
        this.$message.warning('选中数据创建人为【' + record.createUserId + '】，您无权修改')
        return
      }
      if (record.status == 1 || record.status == 2) {
        this.$message.warning('审核中和审核通过的技术信息不可修改')
        return
      }
      let urlJump = this.$router.resolve({ path: `/techEdit?id=` + record.id })
      window.open(urlJump.href, '_blank')
    },
    doDel() {
      if (this.selectionRows == null || this.selectionRows.length != 1) {
        this.$message.warning('请选择1条数据')
        return
      }
      var record = this.selectionRows[0]
      if (record.createUserId != this.userId) {
        this.$message.warning('选中数据创建人为【' + record.createUserId + '】，您无权删除')
        return
      }
      if (record.status == 1 || record.status == 2) {
        this.$message.warning('审核中和审核通过的技术信息不可删除')
        return
      }
      getAction(this.url.delete, { id: record.id }).then((res) => {
        if (res.success) {
          this.$message.success('操作成功')
          this.searchReset()
        } else {
          this.$message.warning('操作失败:', res.message)
        }
      })
    },
    doDetail() {
      if (this.selectedRowKeys == null || this.selectedRowKeys.length != 1) {
        this.$message.warning('请选择1条数据')
        return
      }
      let urlJump = this.$router.resolve({ path: `/techEdit?detail=1&id=` + this.selectedRowKeys[0] })
      window.open(urlJump.href, '_blank')
    },
    doAudit() {
      if (this.selectionRows == null || this.selectionRows.length != 1) {
        this.$message.warning('请选择1条数据')
        return
      }
      var record = this.selectionRows[0]
      if (record.status != 1) {
        this.$message.warning('当前项目状态非待审核')
        return
      }
      if (record.auditUser != this.userId) {
        this.$message.warning('选中数据审核人为【' + record.auditUser + '】，您无权审核')
        return
      }

      let urlJump = this.$router.resolve({ path: `/techEdit?detail=1&audit=1&id=` + record.id })
      window.open(urlJump.href, '_blank')
    },
    doHot() {
      let urlJump = this.$router.resolve({ path: `/techListHot?type=` })
      window.open(urlJump.href, '_blank')
    },
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/hte-main.less';
@import '~@assets/less/hte-main.less';
.page-main {
  .banner {
    background-image: url(../../assets/tech/techHead.png);
  }
  .container {
    .content-list {
      margin-top: 15px;
    }
  }
}
</style>